﻿using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;

using Newtonsoft.Json;

using PLCS.Application.Contracts;
using PLCS.SocialHttpApi.WebServiceControllers;
using PLCS.SocialHttpClient;

using SoapCore;
using SoapCore.Extensibility;

using Volo.Abp;
using Volo.Abp.Modularity;

namespace PLCS.SocialHttpApi;

[DependsOn(
    typeof(PLCSApplicationContractsModule),
    typeof(PLCSSocialHttpClientModule)
    )]
public class PLCSSocialHttpApiModule : AbpModule
{
    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        context.Services.AddScoped<LogActionFilter>();
        context.Services.AddSoapServiceOperationTuner(new LogOperationTuner());
        context.Services.AddSoapCore();
    }

    public override void OnApplicationInitialization(ApplicationInitializationContext context)
    {
        base.OnApplicationInitialization(context);
        var app = context.GetApplicationBuilder();

            app.UseRouting();
            app.UseEndpoints(endpoints =>
            {
                endpoints.UseSoapEndpoint<IWebServiceExample>("/WebServiceExample.asmx", new SoapEncoderOptions(), SoapSerializer.XmlSerializer);
                endpoints.UseSoapEndpoint<IWebServiceExample>("/WebServiceExample", new SoapEncoderOptions(), SoapSerializer.XmlSerializer);
                endpoints.UseSoapEndpoint<IWebServiceExample>("/WebServiceExample.svc", new SoapEncoderOptions(), SoapSerializer.DataContractSerializer);
            });
    }
}